import request from '@/axios';

export const modelList = (current, size, params) => request({
  url: '/zzy-flow/model/list',
  method: 'get',
  params: {
    ...params,
    current,
    size,
  },
});

export const managerList = (current, size, params) => request({
  url: '/zzy-flow/manager/list',
  method: 'get',
  params: {
    ...params,
    current,
    size,
  },
});

export const followList = (current, size, params) => request({
  url: '/zzy-flow/follow/list',
  method: 'get',
  params: {
    ...params,
    current,
    size,
  },
});

export const removeModel = ids => request({
  url: '/zzy-flow/model/remove',
  method: 'post',
  params: {
    ids,
  },
});

export const deployModel = params => request({
  url: '/zzy-flow/model/deploy',
  method: 'post',
  params,
});

export const changeState = params => request({
  url: '/zzy-flow/manager/change-state',
  method: 'post',
  params,
});

export const deployUpload = (category, tenantIds, files) => {
  const formData = new FormData();
  formData.append('category', category);
  formData.append('tenantIds', tenantIds);
  files.forEach((file) => {
    formData.append('files', file);
  });
  return request({
    headers: {
      'Content-Type': 'multipart/form-data',
    },
    url: '/zzy-flow/manager/deploy-upload',
    method: 'post',
    data: formData,
  });
};

export const deleteDeployment = deploymentIds => request({
  url: '/zzy-flow/manager/delete-deployment',
  method: 'post',
  params: {
    deploymentIds,
  },
});

export const deleteProcessInstance = params => request({
  url: '/zzy-flow/follow/delete-process-instance',
  method: 'post',
  params,
});

export const submitModel = data => request({
  url: '/zzy-flow/model/submit',
  method: 'post',
  data,
});

export const detail = params => request({
  url: '/zzy-flow/model/detail',
  method: 'get',
  params,
});

export const modelView = params => request({
  url: '/zzy-flow/process/model-view',
  method: 'get',
  params,
});
